package cn.jsj.cxsys.controller;

import org.springframework.stereotype.*;
import cn.jsj.cxsys.service.*;
import org.springframework.beans.factory.annotation.*;
import java.util.*;
import cn.jsj.cxsys.pojo.*;
import org.springframework.web.bind.annotation.*;
import cn.jsj.cxsys.controller.packageClass.*;

@ResponseBody
@CrossOrigin
@Controller
public class ComputerController
{
    @Autowired
    private ComputerService computerService;

    @RequestMapping(value = { "getLabComputers" }, method = { RequestMethod.POST })
    public List<Computer> getComputersOfLab(@RequestBody final User_Lab tp) {
        if (tp == null) {
            return null;
        }
        return (List<Computer>)this.computerService.getComputersOfLab(tp.getUser(), tp.getLabID(), tp.getPageNum(), tp.getPageSize());
    }

    @RequestMapping(value = { "creatComputer" }, method = { RequestMethod.POST })
    public String addPcFromLab(@RequestBody final Teacher_CreatPc tc) {
        if (tc == null) {
            return "paramLess";
        }
        return this.computerService.addOneComputer(tc.getUser(), tc.getComputer());
    }

    @RequestMapping(value = { "creatComputers" }, method = { RequestMethod.POST })
    public String addComputersInLab(@RequestBody final User_INT_INT uii) {
        if (uii == null) {
            return "paramLess";
        }
        return this.computerService.addComputersInLab(uii.getUser(), uii.getLabID(), uii.getComputerNumber());
    }

    @RequestMapping(value = { "removeComputer" }, method = { RequestMethod.POST })
    public String removePcFromLab(@RequestBody final Teacher_CreatPc tc) {
        if (tc == null) {
            return "paramLess";
        }
        return this.computerService.removeOneComputer(tc.getUser(), tc.getComputer());
    }

    @RequestMapping(value = { "repareComputer" }, method = { RequestMethod.POST })
    public String repareComputer(@RequestBody final User_INT tc) {
        if (tc == null) {
            return "paramLess";
        }
        return this.computerService.setWellOfComputer(tc.getUser(), tc.getId());
    }

    @RequestMapping(value = { "studentSignInComputer" }, method = { RequestMethod.POST })
    public String StudentSignInComputer(@RequestBody final User_INT tc) {
        if (tc == null) {
            return "paramLess";
        }
        return this.computerService.signInComputer(tc.getUser(), tc.getId());
    }

    @RequestMapping(value = { "studentSignOutComputer" }, method = { RequestMethod.POST })
    public String StudnetSignuOutComputer(@RequestBody final User_INT_Str ups) {
        if (ups == null) {
            return "paramLess";
        }
        return this.computerService.signOutComputer(ups.getUser(), ups.getId(), ups.getStr());
    }

    @RequestMapping(value = { "studentBreakComputer" }, method = { RequestMethod.POST })
    public String StudentSetBreakComputer(@RequestBody final User_INT_Str ups) {
        if (ups == null) {
            return "paramLess";
        }
        return this.computerService.setBreakOfComputer(ups.getUser(), ups.getId(), ups.getStr());
    }

    @RequestMapping(value = { "superGetComputer" }, method = { RequestMethod.POST }, params = { "account", "password", "page", "rows" })
    public EasyUIPages<Computer> superGetComputers(@RequestParam("account") final String account, @RequestParam("password") final String password, @RequestParam("page") final int page, @RequestParam("rows") final int rows) {
        final List<Computer> tt = (List<Computer>)this.computerService.getAllComputer(account, password, page, Integer.MAX_VALUE);
        final int computerNumber = this.computerService.getNumberOfComputer();
        return new EasyUIPages<Computer>(computerNumber, tt);
    }
}